
<h1><span class="yiyi-st" id="yiyi-13">numpy.random.RandomState.zipf</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.zipf.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.zipf.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="method">
<dt id="numpy.random.RandomState.zipf"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">RandomState.</code><code class="descname">zipf</code><span class="sig-paren">(</span><em>a</em>, <em>size=None</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">从Zipf分布绘制样本。</span></p>
<p><span class="yiyi-st" id="yiyi-16">样本从具有指定参数<em class="xref py py-obj">a</em>&gt; 1的Zipf分布中绘制。</span></p>
<p><span class="yiyi-st" id="yiyi-17">Zipf分布（也称为zeta分布）是满足Zipf定律的连续概率分布：项目的频率与其在频率表中的秩成反比。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-18">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-19"><strong>a</strong>：float&gt; 1</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">分布参数。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-21"><strong>size</strong>：int或tuple的整数，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">输出形状。</span><span class="yiyi-st" id="yiyi-23">如果给定形状是例如<code class="docutils literal"><span class="pre">（m，</span> <span class="pre">n，</span> <span class="pre">k）</span></code>，则<code class="docutils literal"><span class="pre"> m</span> <span class="pre">*</span> <span class="pre">n</span> <span class="pre">*</span> <span class="pre">k</span></code></span><span class="yiyi-st" id="yiyi-24">默认值为None，在这种情况下返回单个值。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-25">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-26"><strong>samples</strong>：scalar或ndarray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-27">返回的样本大于或等于1。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-28">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-29"><code class="xref py py-obj docutils literal"><span class="pre">scipy.stats.distributions.zipf</span></code></span></dt>
<dd><span class="yiyi-st" id="yiyi-30">概率密度函数，分布或累积密度函数等。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-31">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-32">Zipf分布的概率密度为</span></p>
<div class="math">
<p></p>
</div><p><span class="yiyi-st" id="yiyi-33">其中<img alt="\zeta" class="math" src="../../_images/math/ea2537b0d0cbfff18efbb40720fb87bedfef6b6e.png" style="vertical-align: -3px">是Riemann Zeta函数。</span></p>
<p><span class="yiyi-st" id="yiyi-34">它以美国语言学家乔治&#xB7;金斯利&#xB7;齐普（George Kingsley Zipf）的名字命名，他指出语言样本中任何单词的频率与其在频率表中的排名成反比。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-35">参考文献</span></p>
<table class="docutils citation" frame="void" id="r207" rules="none">
<colgroup><col class="label"><col></colgroup>
<tbody valign="top">
<tr><td class="label"><span class="yiyi-st" id="yiyi-36"><a class="fn-backref" href="#id1">[R207]</a></span></td><td><span class="yiyi-st" id="yiyi-37">Zipf，G.K.，“Selected Studies of the Principle of Relative Frequency in Language”，Cambridge，MA：Harvard Univ。</span><span class="yiyi-st" id="yiyi-38">Press，1932。</span></td></tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-39">例子</span></p>
<p><span class="yiyi-st" id="yiyi-40">从分布绘制样本：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mf">2.</span> <span class="c1"># parameter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">zipf</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-41">显示样本的直方图，以及概率密度函数：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">scipy.special</span> <span class="k">as</span> <span class="nn">sps</span>
<span class="go">Truncate s values at 50 so plot is interesting</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">count</span><span class="p">,</span> <span class="n">bins</span><span class="p">,</span> <span class="n">ignored</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">s</span><span class="o">&lt;</span><span class="mi">50</span><span class="p">],</span> <span class="mi">50</span><span class="p">,</span> <span class="n">normed</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">50.</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="o">**</span><span class="p">(</span><span class="o">-</span><span class="n">a</span><span class="p">)</span><span class="o">/</span><span class="n">sps</span><span class="o">.</span><span class="n">zetac</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">/</span><span class="nb">max</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&apos;r&apos;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-42">（<a class="reference external" href="../../reference/generated/numpy-random-RandomState-zipf-1.py">源代码</a>，<a class="reference external" href="../../reference/generated/numpy-random-RandomState-zipf-1.png">png</a>，<a class="reference external" href="../../reference/generated/numpy-random-RandomState-zipf-1.pdf">pdf</a>）</span></p>
<div class="figure">
<img alt="../../_images/numpy-random-RandomState-zipf-1.png" src="../../_images/numpy-random-RandomState-zipf-1.png">
</div>
</dd></dl>
